package com.example.androidvelostar;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class VeloStarMainActivity extends Activity {
	ArrayList<String> lesDistricts;
	ArrayAdapter<String> unAdaptateur;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_velo_star_main);
		initialisations();
	}

	private void initialisations() {
		ListView listViewDistricts;
		try {
			lesDistricts = Passerelle.getLesDistricts();
			unAdaptateur = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, lesDistricts);
			listViewDistricts = (ListView) findViewById(R.id.listViewDistricts);
			listViewDistricts.setAdapter(unAdaptateur);
			listViewDistricts.setOnItemClickListener(new OnItemClick());
		}
		catch (Exception ex) {
			Toast.makeText(this, R.string.erreurDistricts, Toast.LENGTH_LONG).show();
		}		
	}
		
	private class OnItemClick implements AdapterView.OnItemClickListener {
		@Override
    	public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
			Intent uneIntention;
			uneIntention = new Intent(VeloStarMainActivity.this, StationsActivity.class);
			uneIntention.putExtra(StationsActivity.NOMDISTRICT, lesDistricts.get(position).toString());
			startActivity(uneIntention);
		}
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.velo_star_main, menu);
		return true;
	}

}
